import 'dart:async';
import 'package:flutter/services.dart';

typedef AuthCallBack<T> = void Function(T? value);

class AliAuth {
  static const MethodChannel _channel =
      const MethodChannel('ali_auth');

  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static AuthCallBack? _authCallBack;

  static set authCallBack(AuthCallBack value) {
    _authCallBack = value;
  }

  static void toAuth(String authInfo) {
    _channel.invokeMethod('toAuth', authInfo);
    _channel.setMethodCallHandler(_onMethodCall);
  }
    static Future<void> _onMethodCall(MethodCall call) async {
      switch(call.method) {
        case 'authCallBack':
          if(_authCallBack != null){
            _authCallBack!.call(call.arguments);
          }
          break;
        default:
          return null;
      }
      return null;
    }
}
